home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0061_COD Images.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  48 lines

  1. {
  2. > This doesn't have anything to do with the flicker problem, but I was
  3. > wondering if you could tell me how to scale and rotate .COD images.
  4.  
  5. Although  I  posted  some code to flip COD's horizontally & vertically
  6. some  time  ago,  I  won't make it a regular feature of AniVGA, as I'm
  7. working on compiled bitmaps and thus, altering the "data" after having
  8. it compiled into a procedure is close to impossible...
  9. However,  if  you are speaking about scaling & rotation in MAKES: yes,
  10. one  could  include  it.  To be honest, I was just to lazy to code all
  11. that matrix crap necessary.
  12. For  the  interested  reader: to scale the points (x,y) of a matrix by
  13. some factor f, you just have to apply the matrix
  14. (f 0)
  15. (0 f)
  16. to all its points.
  17. A  rotation  by  an  angle  of  z  degrees  counterclockwise about the
  18. rotation  center (u,v) is more complex: one first has to transform the
  19. point coordinates to homogeneous coordinates (that is: append a one as
  20. the  3rd  component: (x,y) -> (x,y,1); if during computations this 3rd
  21. component  "c"  of  a vector (a,b,c) becomes <>1, then renormalize the
  22. vector to (a/c,b/c,1)).
  23. Having done so, the rotation consists of three steps:
  24. a) make (u,v) the new origin of your pixels (instead of (0,0))
  25. b) rotate the data by z degrees about the new origin (0,0)
  26. c) retransform the true (0,0) origin
  27.  
  28. Step  a)  consists  of  applying the following matrix M1 to the pixels
  29. (x,y,1):
  30. ( 1  0 0)
  31. ( 0  1 0)
  32. (-u -v 1)
  33.  
  34. Likewise, step b) is done by the matrix M2:
  35. ( cos(z) sin(z) 0 )
  36. (-sin(z) cos(z) 0 )
  37. (   0      0    1 )
  38.  
  39. And step c) is done by M3:
  40. ( 1  0 0)
  41. ( 0  1 0)
  42. (+u +v 1)
  43.  
  44. These  three  steps  can  be  squeezed  into one matrix application by
  45. combining  the  three  matrices into one matrix M=M1*M2*M3 (with "*" =
  46. matrix multiplication operator from linear algebra).
  47.  
  48.